<template>
  <div id="app">
    <Topbar :key="TopbarKey" />
    <Header />
    <router-view />
    <Footer />
    <!-- 登录模态框 -->
    <!-- 需要一个状态控制login是否显示 -->
    <Login />
    <!-- 提示框组件 -->
    <transition name="slide">
      <Toast v-show="isShowToast" />
    </transition>
  </div>
</template>

<script>
import Topbar from "@/components/Topbar.vue";
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
import Login from "@/components/Login.vue";
import Toast from "@/components/Toast.vue";

// import axios from "axios";
// import axios from "@/Request/request";
import { JingpinAPI, UserProfilesAPI } from "@/Request/api";
import { mapState } from "vuex";
import router from "./router";

export default {
  data() {
    return {
      TopbarKey: 0,
    };
  },
  computed: {
    ...mapState({
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  // created() {
  //   JingpinAPI()
  //     .then((res) => {
  //       console.log("res2:", res);
  //     })
  //     .catch((err) => {
  //       console.log(err);
  //     });
  // },
  async created() {
    let res = await JingpinAPI();
    // console.log(res);

    // 暂时测试获取用户信息
    // let user = await UserProfilesAPI();
    // console.log("用户信息:", user);
  },
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        if (newVal != oldVal) {
          // key属性的值一变化，就会做组件重载，从而执行created函数
          this.TopbarKey++;
        }
      },
    },
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast,
  },
};

// 获取配置文件
console.log("配置地址:" + process.env.VUE_APP_BASE_URL);
console.log("配置名称:" + process.env.VUE_APP_MY_TEXT);
</script>


<style lang="less">
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
